package com.Java.train.member.controller;

import com.Java.train.common.context.LoginMemberContext;
import com.Java.train.common.response.PageResp;
import com.Java.train.common.response.CommonResp;
import com.Java.train.member.domain.DTO.PassengerDTO;
import com.Java.train.member.domain.Passenger;
import com.Java.train.member.req.PassengerQueryReq;
import com.Java.train.member.service.PassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/passenger")
public class PassengerController {
    @Resource
    private PassengerService passengerService;

    @PostMapping("/save")
    private CommonResp <Object> savePassenger(@Valid @RequestBody Passenger passenger){
        return passengerService.savePassenger(passenger);
    }

    @GetMapping("/query-list")
    private CommonResp<PageResp<PassengerDTO>> queryList(@Valid PassengerQueryReq passengerQueryReq){
        passengerQueryReq.setMemberId(LoginMemberContext.getId());
        return passengerService.queryList(passengerQueryReq);
    }

    @DeleteMapping("/delete/{id}")
    private CommonResp<Object> deleteById(@PathVariable Long id){
        return passengerService.deleteById(id);
    }

    @GetMapping("/query-mine")
    private CommonResp<List<Passenger>> queryMine(){
        return passengerService.queryMine();
    }
}
